
import React , {Component} from "react"
// import { Switch,Button } from 'antd';
import Head from "../../components/head"
import college1 from "../../../assets/images/college1.jpg"
import college2 from "../../../assets/images/college1.png"
import college3 from "../../../assets/images/college2.png"
import college4 from "../../../assets/images/college3.png"
import college5 from "../../../assets/images/college4.png"
import college6 from "../../../assets/images/college5.png"
import college7 from "../../../assets/images/college6.png"
import {change_college} from "../../actions"
import {connect} from "react-redux"
import {secondsFormatYear} from "../../utils/common.js"
@connect(
    state=>({
        colleges:state.colleges,

        imglist:state.imglist
    })
)

export default class College extends Component{
    constructor(props){
        super(props)

    }
    componentWillMount(){
        const {dispatch}=this.props;
        dispatch(change_college("/college",dispatch));
        

    }
    render(){
        const {history} = this.props;
        var collegeCounts = [];
        var show=true;
        if(this.props.colleges!=""){
            this.props.colleges.forEach(item=>{
                if(!item.imglist){
                    item.imglist = []
                }
                collegeCounts.push(item)
            })
        }
        // console.log(collegeCounts)
        var coll;
        if(collegeCounts){
        coll =  collegeCounts.map((collegeCount,coll)=>{
            var times=secondsFormatYear(collegeCount.dateline*1000,"MM-dd HH:mm")
            return ( 
                <div className="collegeContent clearfix" key={coll}>
                    <div className="contentLeft">
                        <img src={ collegeCount.avatar} alt=""/>
                    </div>
                    <div className="contentRight">
                        <h2>{collegeCount.subject}</h2>
                        <div>
                            <ul className="contentUl" style={{display:!!collegeCount.imglist.length?"block":'none'}}>
                               { collegeCount.imglist.map((img,idx)=>{
                                    return (
                                        <li key={idx}>
                                            <img src={img.url}/>  
                                        </li>
                                    )
                                })}
                            </ul>
                        </div>
                        <div className="contentFoot">
                            <span>
                                {times}
                            </span>
                          
                            <span className="footdetail">{collegeCount.username}</span>
                        </div>
                    </div>

                </div>
              )
            })
        }
        return (
           <div className="college">
                <Head/>
                <h1 className="collegeTitle">
                    <img src={college1}/>
                </h1>
                <ul className="collegeNav clearfix">
                    <li><img src={college2}/></li>
                    <li><img src={college3}/></li>
                    <li><img src={college4}/></li>
                    <li><img src={college5}/></li>
                    <li><img src={college6}/></li>
                    <li><img src={college7}/></li>
                </ul>
                <div>
                    { coll}
                </div>

           </div>
        )
    }
}